% Define x as depth direction - y as azimuth
% Position the points
scatterers(:,1) = linspace(30e-3,100e-3,20);
scatterers(:,2) = zeros(20,1);

% Define the transmit pulse
fs = 50e6; % Hz
f = 2.5e6; % Hz
c = 1530; % m/s
pulse_length = 2e-6; %s
sigma_r = 2.2e-7; %s

% Define the transmit pulse of the current system
spatial_f = 2*f/c;
spatial_fs = c/2/fs;
spatial_pulse_length = pulse_length*c/2;
spatial_sigma_r = sigma_r*c/2;

pulse = [0:spatial_fs:spatial_pulse_length];
pulse = exp(-0.5*(pulse-spatial_pulse_length/2).^2 / spatial_sigma_r^2) .* cos(2*pi*spatial_f*pulse);

% Run through all image lines
line_pos = linspace(-7e-3,7e-3,30);
T = zeros(round((100e-3 - 30e-3)/spatial_fs),30);

% Define the lateral PSF
lateral_sigma = 1e-3;
%PSF = exp(-0.5*(line_pos).^2 / lateral_sigma^2);
for i=1:length(line_pos)
       distance_from_line = scatterers(:,2) - line_pos(i);
       for scatterer_nr = 1:length(scatterers)
           T(round((scatterers(scatterer_nr,1) - 30e-3)/spatial_fs)+1,i) = exp(-0.5*distance_from_line(scatterer_nr).^2/lateral_sigma^2);
       end
       RF(:,i) = conv(pulse,T(:,i));
end
%RF = conv2(pulse,T); % Alternative (faster) solution (conv can be taken
%out of the for loop)

 % Make a gray scale image
figure;imagesc(line_pos,linspace(30e-3,100e-3,length(RF)),abs(hilbert(RF)));colormap(gray);
